/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.imenu.ejb;

import com.imenu.entity.ImenuMenu;
import com.imenu.entity.ImenuStore;
import com.imenu.entity.ImenuTag;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Yunzi
 */
@Stateless
public class ImenuTagFacade extends AbstractFacade<ImenuTag> {
    @PersistenceContext(unitName = "iMenuPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public ImenuTagFacade() {
        super(ImenuTag.class);
    }
    
    public List<ImenuTag> findByStoreId(ImenuStore storeId) {
        Query q = getEntityManager().createNamedQuery("ImenuTag.findByStoreId");
        q.setParameter("storeId", storeId);
        return q.getResultList();
    }
    @EJB
    ImenuMenuFacade menuFacade;
    public List<ImenuTag> findByMenuId(Integer menuId) {
        ImenuMenu menu = menuFacade.find(menuId);
        if(menu != null){
            return this.findByStoreId(menu.getStore());
        }
        return new ArrayList<ImenuTag>();
    }
}
